package com.dongdongkeji.base.bean.dto;

import com.dongdongkeji.base.bean.ListPageEntity;
import com.dongdongkeji.base.interfaces.Mapper;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页列表数据
 *
 * Author: ChenJing
 * Date: 2017-04-24 下午 8:14
 * Version: 1.0
 * Desc: T：转换类， R：转换目标类
 */

public class ListPageDTO<T extends Mapper<R>, R> implements Mapper<ListPageEntity<R>> {

    private int pages;
    private List<T> list;

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    @Override
    public ListPageEntity<R> transform() {
        ListPageEntity<R> listResult = new ListPageEntity<R>();
        listResult.setMaxPage(pages);
        List<R> listR = new ArrayList<>();
        if (list != null) {
            for (T t : list) {
                listR.add(t.transform());
            }
        }
        listResult.setList(listR);
        return listResult;
    }
}
